find_package(Protobuf REQUIRED)
find_package(gRPC CONFIG REQUIRED)

file(GLOB_RECURSE ProtoFiles ./*.proto)

add_library(ProtoTarget ${ProtoFiles})
target_link_libraries(ProtoTarget
        PUBLIC protobuf::libprotobuf gRPC::grpc gRPC::grpc++
)
target_include_directories(ProtoTarget
        PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
)

#generate pb.h/pb.cc
protobuf_generate(
        TARGET ProtoTarget
        LANGUAGE cpp
)

#generate .grpc.pb.h/.grpc.pb.cc
protobuf_generate(
        TARGET ProtoTarget
        LANGUAGE grpc
        GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
        PLUGIN protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
)

